package com.example.demomodule2;


import java.util.List;





import android.content.Context;
import android.view.LayoutInflater;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import android.widget.ImageView;
import android.widget.TextView;

import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;


public class DataAdapter extends BaseAdapter {
	Context context;
	int resId;
	List<Country> countries;
	public DataAdapter(Context context, int resId, List<Country> countries) {
		// TODO Auto-generated constructor stub
		this.context = context;
		this.resId = resId;
		this.countries = countries;
	}

		
	

	
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return countries.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View view = null;
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		
		view = inflater.inflate(resId,null);
		
		TextView tvNameEn = (TextView) view.findViewById(R.id.tvNameEn);
		TextView tvNameVi = (TextView) view.findViewById(R.id.tvNameVi);
		ImageView ivFlag = (ImageView) view.findViewById(R.id.ivFlag);
		
		tvNameEn.setText(countries.get(position).getEnName());
		tvNameVi.setText(countries.get(position).getViName());
		ivFlag.setImageResource(countries.get(position).getIvflag());
		
		return view;
		

	
	}

	class ViewHolder{
		TextView tvNameEn;
		TextView tvNameVi;
		TextView tvPop;
		ImageView ivFlag;

		void init(View convertView, int position)
		{
			tvNameEn = (TextView) convertView.findViewById(R.id.tvNameEn);
			tvNameVi = (TextView) convertView.findViewById(R.id.tvNameVi);
			tvPop = (TextView) convertView.findViewById(R.id.population_tv);
			ivFlag = (ImageView) convertView.findViewById(R.id.ivFlag);
			tvNameEn.setTag(position + "");
		}

		void setContent(Country country)
		{
			tvNameEn.setText(country.getEnName());
			tvNameVi.setText(country.getViName());
			tvPop.setText(country.getPop()+"");
			ivFlag.setImageResource(country.getIvflag());
			
		}



	}
}
